﻿@model IEnumerable<CmsDashboard>
           
@{
    Layout = "~/Templates/BaseAdminTemplate.cshtml";
}           

@functions 
{
    string DashboardWidth(int width)
    {
        return width > 0 ?
            string.Format(@"width:{0}px", width) :
            string.Empty;
    }
    }
    
@RenderSection("Description")
@{Html.RenderPartial("ErrorPanel");}
 
@if (Model != null)
{
<div class="b-masonry">
	@foreach (var item in Model)
 {
    <div class="b-form  b-form_bordered b-form_theme_white" style="@DashboardWidth(item.Width)">
	    <div class="b-form__head b-form__head_grey">
		    <a href="#" class="b-icon b-icon_expand b-icon_slider b-icon_expand_min"></a>
			<h3 class="b-form__title">@item.DashboardName</h3>
	    </div>
	    <div class="b-form__body">
	 		<input type="hidden" class="dashboard_load_url" value="@item.LoadUrl" />
	    </div>
	</div>
 }
</div>
}

@section scriptBlock{
<script>
    var $container = $('.b-masonry');
    $LAB.
        script(function () {
            $container.masonry({
                itemSelector: '.b-form',
                isAnimated: !Modernizr.csstransitions
            });
        })
        .wait()
        .script(function () {
            $(':hidden.dashboard_load_url').each(function () {
                var $el = $(this);
                var $parentEl = $el.parent();
                $parentEl.addClass('b-loading_small');
                $.ajax({
                    cache: false,
                    url: $el.val(),
                    success: function (data) {
                        $parentEl.html(data);
                        $parentEl.removeClass('b-loading_small');
                        $container.imagesLoaded(function () {
                            $container.masonry('reload');
                        });
                    }
                });
            });
        });

        $(function () {
            $.post($.cmsAdminOptions.options.knownUrls.siteWorkflowPanelUrl)
                .success(function (data) {
                    if (data === 1) return;
                    viewModel.viewEventModel.addEvent({ eventTitle: "Other sites requiring attention", eventBody: data });
                });
        });
</script>
}